package com.ymatou.iapi.productmanager.testcase;

import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.base.Strings;
import com.ymatou.iapi.productmanager.parameter.BrandDto;
import com.ymatou.iapi.productmanager.parameter.BrandDtoV2;
import com.ymatou.iapi.productmanager.parameter.BrandPo;
import com.ymatou.iapi.productmanager.parameter.GetCommonBrandsForUserBean;
import com.ymatou.iapi.productmanager.parameter.SellerBrand;
import com.ymatou.iapi.productmanager.service.GetBrandsCall;
import com.ymatou.iapi.productmanager.service.GetCommonBrandsForUserCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.App_ClientConfigWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取用户公共品牌信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCommonBrandsForUser{
	private static GetCommonBrandsForUserBean getcommonbrandsforuserBean;
	private static GetCommonBrandsForUserCall getcommonbrandsforuserCall;
	private static Integer userId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户公共品牌信息");
	}

	@Before
	public void caseUp() {
		getcommonbrandsforuserBean=new GetCommonBrandsForUserBean();
		getcommonbrandsforuserCall=new GetCommonBrandsForUserCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcommonbrandsforuserCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCommonBrandsForUser_001() {
		Logger.start(true,"获取用户公共品牌信息");
		try {
			getcommonbrandsforuserBean.setUserId(userId);
			getcommonbrandsforuserCall.setData(getcommonbrandsforuserBean);
			getcommonbrandsforuserCall.callService();
			List<BrandDtoV2> sbrand = getcommonbrandsforuserCall.getBrands();
			Logger.verifyEquals("200", getcommonbrandsforuserCall.getString("Code"), "验证Code");
			List<SellerBrand> sellerBrands = new App_ClientConfigWapper().getSellerBrand(userId);
			List<Integer> brandIds = sellerBrands.stream().map(SellerBrand::getComBrandId).collect(Collectors.toList());
			List<BrandPo> brands = new YmtProductsIWapper().getCommonBrands(0, brandIds);
			for(int i = 0;i<sbrand.size();i++){
				for(int j = 0;j<brands.size();j++){
					if(sbrand.get(i).getBrandId() == brands.get(j).getiBrandId()){
						Logger.verifyEquals(sbrand.get(i).getBrandName(), brands.get(j).getsBrandEn(), "验证BrandEnName");
						Logger.verifyEquals(sbrand.get(i).getBrandNameCH(), brands.get(j).getsBrand(), "验证BrandName");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCommonBrandsForUser_002() {
		Logger.start(true,"获取用户公共品牌信息,不传买手编号");
		try {
			getcommonbrandsforuserCall.setData(getcommonbrandsforuserBean);
			getcommonbrandsforuserCall.callService();
			Logger.verifyEquals("400", getcommonbrandsforuserCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}